home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / H-K / Icon.sample.cpt / sieve.icn < prev    next >
Text File  |  1988-04-07  |  544b  |  20 lines

  1. #
  2. #          S I E V E   O F   E R A T O S T H E N E S
  3. #
  4.  
  5. #  This program illustrates the use of sets in implementing the
  6. #  classical sieve algorithm for computing prime numbers.
  7.  
  8. procedure main(a)
  9.    local limit, s, i
  10.    limit := integer(a[1]) |100
  11.    s := set()
  12.    every insert(s,1 to limit)
  13.    every member(s,i := 2 to limit) do
  14.       every delete(s,i + i to limit by i)
  15.    primes := sort(s)
  16.    write("There are ",*primes," primes in the first ",limit," integers.")
  17.    write("The primes are:")
  18.    every write(right(!primes,*limit + 1))
  19. end
  20.